home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 24 / Amiga Format AFCD24 (Feb 1998, Issue 108).iso / -seriously_amiga- / shareware / programming / other / pmdev / demos / disable.c < prev    next >
C/C++ Source or Header  |  1998-01-05  |  3KB  |  102 lines

  1. //
  2. // $VER: Disable.c 2.0 (12.8.97)
  3. //
  4. // Popup Menu example program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Run and click the mouse in the window!
  10. //
  11.  
  12. #include <intuition/intuition.h>
  13.  
  14. #include <clib/intuition_protos.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21.  
  22. #include <libraries/pm.h>
  23. #include <proto/pm.h>
  24.  
  25. struct IntuitionBase    *IntuitionBase;
  26. struct GfxBase        *GfxBase;
  27. struct PopupMenuBase    *PopupMenuBase;
  28.  
  29. struct Window *w;    // This window is only needed to find out when and where the menu should appear.
  30.             // The font in this window's rastport will be used for the menu.
  31.  
  32. void main()
  33. {
  34.     BOOL r=TRUE;
  35.     struct IntuiMessage *im,imsg;
  36.     struct PopupMenu *p;
  37.  
  38.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  39.     if(PopupMenuBase) {
  40.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  41.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  42.  
  43.         p=PMMenu("Plain Simple Menu!"),    // Create a very simple menu...
  44.  
  45.             PMCheckItem("Enable quit?",10),                                PMEnd,
  46.  
  47.             PMTitleBar,                                        PMEnd,
  48.  
  49.             PMItem("Quit"),        PM_Sub,
  50.                 MakeMenu(
  51.                     PMItem("Quit"),        PM_Disabled,    TRUE,    PM_UserData,    5,    PM_ID,    15,    PMEnd,
  52.                 PMEnd, /* MakeMenu */
  53.  
  54.             PMEnd, /* PMItem */
  55.  
  56.         End; /* PMMenu */
  57.  
  58.         if(p) {
  59.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,    // Open a little window
  60.                     WA_RMBTrap,    TRUE,
  61.                     WA_DragBar,    TRUE,
  62.                     WA_Width,    150,
  63.                     WA_Height,    100,
  64.                     WA_Left,    0,
  65.                     WA_Top,        0,
  66.                     WA_Title,    "Disable & Enable",
  67.                     WA_CloseGadget,    TRUE,
  68.                     TAG_DONE);
  69.             if(w) {
  70.                 while(r) {
  71.                     WaitPort(w->UserPort);                        // Wait for a message
  72.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  73.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  74.                         ReplyMsg((struct Message *)im);                // Reply the message
  75.  
  76.                         switch(imsg.Class) {
  77.                             case IDCMP_CLOSEWINDOW: r=FALSE; break;
  78.                             case IDCMP_MOUSEBUTTONS:            // The user has hit a mousebutton - time to open the menu!
  79.                                 r=(BOOL)((ULONG)(PM_OpenPopupMenu(w,
  80.                                         PM_Menu,        p,
  81.                                         PM_Code,        imsg.Code,
  82.                                         TAG_DONE))-5);
  83.                                         
  84.                                 if(PM_ItemChecked(p,10)) {    // See if "Enable quit?" is checked
  85.                                     // Find the item and enable it
  86.                                     PM_SetItemAttrs(PM_FindItem(p, 15), PM_Disabled, FALSE, TAG_DONE);
  87.                                 } else {
  88.                                     // Find the item and disable it
  89.                                     PM_SetItemAttrs(PM_FindItem(p, 15), PM_Disabled, TRUE, TAG_DONE);
  90.                                 }
  91.                             break;
  92.                         }
  93.                     }
  94.                 }
  95.                 CloseWindow(w);
  96.             } else printf("Window error!\n");
  97.             PM_FreePopupMenu(p);
  98.         } else printf("Menu error!\n");
  99.         CloseLibrary((struct Library *)PopupMenuBase);
  100.     }
  101. }
  102.